package com.wbb.aop;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class AopLog {
    @Pointcut("execution(public * com.wbb.service.impl.*.*(..)) || @annotation(com.wbb.aop.AnLog)")
    public void pointcut(){}

  //前置通知
    @Before(value = "pointcut()")
    public void before(JoinPoint point){
        // 方法执行之前,打印方法名,方法的参数
        // 方法的参数
        Object[] args = point.getArgs();
        // 方法名:
        Signature signature = point.getSignature();

        log.info("方法名为: {},方法参数为: {}",signature,args);
    }

  // 后置通知, 打印返回值内容
    @AfterReturning(value = "pointcut()",returning = "result")
    public void after(Object result){
        // 转成jsonStr
        log.info("返回值为:{}", JSONObject.toJSONString(result));
    }
}
